home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
351-375
/
373
/
multiplot
/
source
/
mplot_src
/
src.zoo
/
plot.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-02
|
24KB
|
872 lines
#include "struct.h"
#include "plot.h"
#include <graphics/gfxmacros.h>
extern struct Window *window;
extern struct TextBox *ExtraText;
extern int CHARWIDTH;
extern int CHARHEIGHT;
extern int LMARGIN; /* CHARWIDTH x 7 */
extern int RMARGIN;
extern int TMARGIN;
extern int BMARGIN; /* CHARHEIGHT x 3 */
extern int XMINP; /* LMARGIN */
extern int XMAXP; /* MAXHORIZ - RMARGIN */
extern int YMAXP; /* MAXVERT - TMARGIN */
extern int YMINP; /* BMARGIN */
int OLD_XMINP;
int CALC_XMIN;
int CALC_YMIN;
int OLD_YMIN;
/*** PLOT TYPES ***/
#define LINEPLOT 0
#define POINTPLOT 1
#define BOTHPLOT 2
#define STEP 3
extern int debug;
extern int MAXVERT;
extern int MAXHORIZ;
extern FFP fround();
extern struct Pict *Pict;
extern struct Menu Project;
#define ON 1
#define OFF 0
struct TextAttr xfont = { "Courier.font", 14, 0, 1 };
struct TextAttr yfont = { "Courier.font", 14, 0, 1 };
struct TextAttr tfont = { "Courier.font", 24, 0, 1 };
struct TextAttr lfont = { "Courier.font", 14, 0, 1 };
struct IntuiText XITLabel = {
1,0,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&xfont, /* font pointer or NULL for default */
NULL, /* pointer to text */
NULL /* next IntuiText structure */
};
struct IntuiText YITLabel = {
1,0,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&yfont, /* font pointer or NULL for default */
NULL, /* pointer to text */
NULL /* next IntuiText structure */
};
struct IntuiText TITLabel = {
1,0,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&tfont, /* font pointer or NULL for default */
NULL, /* pointer to text */
NULL /* next IntuiText structure */
};
struct IntuiText Legend = {
1,0,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&lfont, /* font pointer or NULL for default */
NULL, /* pointer to text */
NULL /* next IntuiText structure */
};
int OLD_XMINP;
int CALC_XMIN;
int CALC_YMIN;
int OLD_YMINP;
struct TextFont *xf;
struct TextFont *yf;
struct TextFont *tf;
struct TextFont *lf;
AllowForText(Pict)
struct Pict *Pict;
{
int i,n=3;
struct Tics *Tics;
char tmpstr[20];
struct Plot *Plot;
OLD_YMINP=YMINP;
if (strlen(Pict->XLabel->String)) {
if (!xf) xf =(struct TextFont *) OpenDiskFont(&xfont);
if (xf) {
YMINP = BMARGIN=( xfont.ta_YSize +CHARHEIGHT *4);
}
else YMINP = BMARGIN= CHARHEIGHT *5;
}
else YMINP=BMARGIN= CHARHEIGHT*3;
if (OLD_YMINP!=YMINP) CALC_YMIN=TRUE;
if (strlen(Pict->Title)) {
if (!tf) tf=(struct TextFont *) OpenDiskFont(&tfont);
if (tf) {
YMAXP = MAXVERT - (TMARGIN=( tfont.ta_YSize +CHARHEIGHT *2));
}
else YMAXP = MAXVERT- (TMARGIN=CHARHEIGHT*4);
}
else YMAXP=MAXVERT-(TMARGIN=CHARHEIGHT*2);
if (!lf) lf=(struct TextFont *) OpenDiskFont(&lfont);
RMARGIN=2;
if (Pict->RMargin) {
Plot=Pict->Plot;
while (Plot)
{
Legend.IText=Plot->Legend->String;
if (lf) { RMARGIN= max(RMARGIN,IntuiTextLength(&Legend)); }
else RMARGIN= max(RMARGIN,(strlen(Plot->Legend->String)*CHARWIDTH));
while (Plot->Continued) Plot=Plot->NextPlot;
Plot=Plot->NextPlot;
}
if (RMARGIN>2) {RMARGIN+=48;Pict->RMargin=TRUE;}
else Pict->RMargin=FALSE;
}
XMAXP=MAXHORIZ-RMARGIN;
OLD_XMINP=XMINP;
Tics = Pict->Tics;
for (i=0; i < Tics->NY; i++) { n=max(n,GetString(&tmpstr,Tics->y[i]));}
XMINP=(n+2)*CHARWIDTH;
if (strlen(Pict->YLabel->String)) {
if (!yf) yf=(struct TextFont *) OpenDiskFont(&yfont);
YITLabel.IText=Pict->YLabel->String;
if (yf) { XMINP=LMARGIN=XMINP+CHARWIDTH+abs(IntuiTextLength(&YITLabel)/strlen(Pict->YLabel->String)); }
else XMINP=LMARGIN=XMINP+(2*CHARWIDTH);
}
if (OLD_XMINP!=XMINP) CALC_XMIN=TRUE;
return(0);
}
void CloseFonts()
{
if (xf) CloseFont(xf);
if (lf) CloseFont(lf);
if (yf) CloseFont(yf);
if (tf) CloseFont(tf);
}
/**********************/
void GetDataLimits(Pict)
struct Pict *Pict;
{
short i;
FFP *x, *y, *e;
struct Plot *Plot;
FFP xmin, xmax, ymin, ymax;
xmin = (ymin = FFPLARGE);
xmax = (ymax = -FFPLARGE);
Plot = Pict->Plot;
while (Plot) {
if (Plot->Enabled) {
i = 0; x = Plot->x; y = Plot->y;
if (Pict->ShowErr) e = Plot->e;
while (i++ < Plot->NPts) {
xmax = max(*x,xmax);
xmin = min(*x,xmin);
x++;
if (Pict->ShowErr) {
ymax = max((*y + *e), ymax);
ymin = min((*y - *e), ymin);
y++; e++;
}
else {
ymax = max(*y,ymax);
ymin = min(*y,ymin);
y++;
}
}
}
Plot = Plot->NextPlot;
}
if (!Pict->XRegionLock)
{Pict->CurrReg->XMax = xmax; Pict->CurrReg->XMin = xmin;}
if (!Pict->YRegionLock)
{Pict->CurrReg->YMax = ymax; Pict->CurrReg->YMin = ymin;}
}
void GetPlotLimits(Pict,Reg)
struct PlotRegion *Reg;
struct Pict *Pict;
{
short i;
FFP *x, *y, *e;
struct Plot *Plot;
FFP xmin, xmax, ymin, ymax;
xmin = (ymin = FFPLARGE);
xmax = (ymax = -FFPLARGE);
Plot = Pict->Plot;
while (Plot) {
i = 0; x = Plot->x; y = Plot->y;
if (Pict->ShowErr) e = Plot->e;
while (i++ < Plot->NPts) {
xmax = max(*x,xmax);
xmin = min(*x,xmin);
x++;
if (Pict->ShowErr) {
ymax = max((*y + *e), ymax);
ymin = min((*y - *e), ymin);
y++; e++;
}
else {
ymax = max(*y,ymax);
ymin = min(*y,ymin);
y++;
}
}
Plot = Plot->NextPlot;
}
Reg->XMax=xmax; Reg->XMin=xmin;
Reg->YMax=ymax; Reg->YMin=ymin;
}
/*****************************************/
void AdjustForTics(dmin, dmax, ntics, tics)
FFP *dmin, *dmax, *tics;
short ntics;
{
FFP tmp, fract, f_ntics;
short i;
f_ntics = (FFP)(ntics);
fract = (FFP)(ntics+1) / f_ntics;
/*** adjust data limits to make "nice" numbers for tic marks ***/
tmp = *dmin - (*dmax - *dmin) / 5;
*dmin = fround( *dmin, DOWN, tmp);
tmp = (*dmax - *dmin) / f_ntics;
tmp = fround( tmp, UP, (tmp * fract) );
*dmax = *dmin + tmp * f_ntics;
tics[0] = fround( *dmin, UP, *dmin+tmp/2);
for (i=1; i<ntics; i++) {
tics[i] = tics[i-1] + tmp;
}
}
/**************/
void Scale(Pict)
struct Pict *Pict;
{
struct Plot *Plot;
struct PlotRegion *Reg;
struct Tics *Tics;
register short i, *xp, *yp;
register FFP *x, *y, xmin, ymin, xscale, yscale;
short *ep, err, err_sav = TRUE;
FFP *e, xmax, ymax;
Reg = Pict->CurrReg;
xmin = Reg->XMin; xmax = Reg->XMax;
ymin = Reg->YMin; ymax = Reg->YMax;
if (FFPSAME(xmax,xmin))
{Message("Scaling error: X to small"); xscale = FFPLARGE;}
else
Pict->XScale = xscale = (FFP)(XMAXP-XMINP) / (xmax - xmin);
if (FFPSAME(ymax,ymin))
{Message("Scaling error: Y to small"); yscale = FFPLARGE;}
else
Pict->YScale = yscale = (FFP)(YMAXP-YMINP) / (ymax - ymin);
#define NEW_X_REGION ( !FFPSAME(Reg->XMin,xmin) || !FFPSAME(Reg->XMax,xmax) )
#define NEW_Y_REGION ( !FFPSAME(Reg->YMin,ymin) || !FFPSAME(Reg->YMax,ymax) )
/* DATA */
Plot = Pict->Plot;
err = Pict->ShowErr;
while (Plot) {
if (Plot->Enabled) {
Reg = Plot->Reg;
if ((NEW_X_REGION)||(CALC_XMIN)) {
x = Plot->x; xp = Plot->xp;
for (i = 0; i < Plot->NPts; i++) {
*xp++ = XMINP + (short)((*x++ - xmin) * xscale);
}
Reg->XMin = xmin; Reg->XMax = xmax;
}
if ( (NEW_Y_REGION) || (err_sav!=err) || (CALC_YMIN)) {
y = Plot->y; yp = Plot->yp; e = Plot->e; ep = Plot->ep;
for (i = 0; i < Plot->NPts; i++) {
*yp++ = YMINP + (short)((*y++ - ymin) * yscale);
if (err) {
*ep++ = (short)(*e++ * yscale);
}
}
Reg->YMin = ymin; Reg->YMax = ymax;
}
}
Plot = Plot->NextPlot;
}
CALC_YMIN=CALC_XMIN=FALSE;
err_sav = err;
/* TICS */
Tics = Pict->Tics;
for (i=0; i < Tics->NX; i++)
Tics->xp[i] = XMINP + (short)((Tics->x[i] - xmin) * xscale);
for (i=0; i < Tics->NY; i++)
Tics->yp[i] = YMINP + (short)((Tics->y[i] - ymin) * yscale);
}
/**********************/
void DrawAxes(Tics,Grid)
struct Tics *Tics; short Grid;
{
short *xp, *yp, n, tmpx, tmpy, i;
char tmpstr[20];
struct Plot *Plot;
struct TextBox *TempText;
/*** DRAW BORDER ***/
if ((Grid>1)&&(Grid<5)) {
SetDrMd(rp, JAM1);
SetAPen(rp,2);
SetOPen(rp,1);
if (Pict->RMargin) PRectFill(XMINP-1,YMINP-1,MAXHORIZ-1,YMAXP+1);
else PRectFill(XMINP-1,YMINP-1,XMAXP+1,YMAXP+1);
PRectFill(XMINP,YMINP,XMAXP,YMAXP);
}
else if (Grid<2) {
SetDrMd(rp, JAM1);
SetAPen(rp,2);
SetOPen(rp,2);
PRectFill(XMINP-1,YMINP-1,MAXHORIZ-1,YMAXP+1);
SetAPen(rp,1);
PMove(XMAXP+1,YMINP-1); PDraw(XMINP-1,YMINP-1); PDraw(XMINP-1,YMAXP+1);
PMove(XMAXP+1,YMINP); PDraw(XMINP,YMINP); PDraw(XMINP,YMAXP+1);
}
/*** DRAW TICS/GRID ***/
xp=Tics->xp; yp=Tics->yp;
for (i=0; i < Tics->NX; i++) {
if (Grid==2) {
SetAPen(rp,3);
if (xp[i]>XMINP) {PMove(xp[i],YMINP+1); PDraw(xp[i],YMAXP-1);}
}
else {
SetAPen(rp,1);
if (xp[i]>XMINP)
{
if ((Grid==0)||(Grid==3)) {PMove(xp[i],YMINP+1); PDraw(xp[i],YMINP+X_TIC_SIZE);}
if (Grid==3) {PMove(xp[i],YMAXP-1); PDraw(xp[i],YMAXP-X_TIC_SIZE);}
}
}
}
for (i=0; i < Tics->NY; i++) {
if (Grid==2) {
SetAPen(rp,3);
if (yp[i]>YMINP) {PMove(XMINP+1,yp[i]); PDraw(XMAXP-1,yp[i]);}
}
else {
SetAPen(rp,1);
if (yp[i]>YMINP)
{
if ((Grid==0)||(Grid==3)) {PMove(XMINP+1,yp[i]); PDraw(XMINP+Y_TIC_SIZE,yp[i]);}
if (Grid==3) {PMove(XMAXP-1,yp[i]); PDraw(XMAXP-Y_TIC_SIZE,yp[i]);}
}
}
}
/*** PRINT TIC VALUES AND TEXT ***/
SetAPen(rp,1);
if ((Grid==0)||(Grid==2)||(Grid==3))
{
for (i=0; i < Tics->NX; i++) {
n=GetString(&tmpstr,Tics->x[i]);
tmpx = Tics->xp[i] - (n/2) * CHARWIDTH;
tmpy = max(0, YMINP-2*CHARHEIGHT);
PMove(tmpx, tmpy); Text(rp,tmpstr,n);
}
}
XITLabel.IText=Pict->XLabel->String;
n=IntuiTextLength(&XITLabel);
tmpx=( (LMARGIN + (XMAXP-XMINP)/2) - (n/2) );
tmpy = (MAXVERT-xfont.ta_YSize-2);
PrintIText(rp,&XITLabel,tmpx,tmpy);
TITLabel.IText=Pict->Title->String;
n=IntuiTextLength(&TITLabel);
tmpx=( (MAXHORIZ/2) - (n/2) );
tmpy = (CHARHEIGHT*2);
PrintIText(rp,&TITLabel,tmpx,tmpy);
if (strlen(Pict->YLabel->String))
{
if (yf) { PrintVText(rp,&YITLabel,2,(MAXVERT/2)-strlen(Pict->YLabel->String)*(yfont.ta_YSize+1)/2); }
else PrintVText(rp,&YITLabel,2,(MAXVERT/2)-strlen(Pict->YLabel->String)*(CHARHEIGHT+1)/2);
}
if ((Grid==0)||(Grid==2)||(Grid==3))
{
for (i=0; i < Tics->NY; i++) {
n=GetString(&tmpstr,Tics->y[i]);
tmpx = max(0, XMINP-(n+1)*CHARWIDTH);
PMove(tmpx, Tics->yp[i]-CHARHEIGHT/2); Text(rp,tmpstr,n);
}
}
SetDrMd(rp, JAM1); SetAPen(rp,1);
Plot=Pict->Plot;
while (Plot)
{
if ((Plot->Enabled)&&(strlen(Plot->Legend->String)>0))
{
Legend.IText=Plot->Legend->String;
if (lf) PrintIText(rp,&Legend,Plot->Legend->x+34,MAXVERT-Plot->Legend->y-abs(lfont.ta_YSize/2));
else PrintIText(rp,&Legend,Plot->Legend->x+34,MAXVERT-Plot->Legend->y-abs(CHARHEIGHT/2));
}
while (Plot->Continued) Plot=Plot->NextPlot;
Plot=Plot->NextPlot;
}
TempText=ExtraText;
while (TempText)
{
Legend.IText=TempText->String;
if (lf) PrintIText(rp,&Legend,TempText->x,MAXVERT-TempText->y-abs(lfont.ta_YSize/2));
else PrintIText(rp,&Legend,TempText->x,MAXVERT-TempText->y-abs(CHARHEIGHT/2));
TempText=TempText->NextText;
}
}
PlotPoint(Plot,x,y,m,n,Flag)
struct Plot *Plot;
short *x, *y, m, n, Flag;
{
void PDrawBox(), PDrawPlus(), PDrawEggs(), PDrawKite(), PDrawTri();
switch (abs(n)) {
case 0: break;
case 1:
if (Flag || ClipPoint(*x,*y,XMINP,YMINP,XMAXP,YMAXP))
{
PWritePixel(*x, *y);
break;
}
case 2:
if (Flag || ClipPoint(*x,*y,XMINP,YMINP,XMAXP,YMAXP))
{
PWritePixel(*x, *y);
PWritePixel(*x, *y+1);
break;
}
case 3:
if (Flag || ClipPoint(*x,*y,XMINP,YMINP,XMAXP,YMAXP))
{
PRectFill(*x, *y, *x+1, *y+1);
break;
}
default:
if (Flag || ClipPoint(*x,*y,XMINP,YMINP,XMAXP,YMAXP))
{
switch (Plot->PointType) {
case 1: PDrawTri(m,*x,*y); break;
case 2: PDrawKite(m,*x,*y); break;
case 3: PDrawEggs(m,*x,*y); break;
case 4: PDrawEggs(m,*x,*y); /* Fall through (fancy, huh?) */
case 5: PDrawPlus(m,*x,*y); break;
case 6:
default: PDrawBox(m,*x,*y); break;
}
}
break;
}
return(0);
}
CheckLegend(Pict)
struct Pict *Pict;
{
int j=0;
struct Plot *Plot;
struct TextBox *TempText;
Plot=Pict->Plot;
while (Plot)
{
if ((Plot->Enabled)&&(strlen(Plot->Legend->String)>0)&&(Plot->Legend->x)&&(Plot->Legend->y))
j=j+20;
while (Plot->Continued) Plot=Plot->NextPlot;
Plot=Plot->NextPlot;
}
Plot=Pict->Plot;
while (Plot)
{
if ((Plot->Enabled)&&(strlen(Plot->Legend->String)>0)&&(!Plot->Legend->x)&&(!Plot->Legend->y))
{
if (!Plot->Legend->x) Plot->Legend->x=XMAXP+10;
if (!Plot->Legend->y) Plot->Legend->y=abs(YMAXP/4*3)-j;
j=j+20;
}
while (Plot->Continued) Plot=Plot->NextPlot;
Plot=Plot->NextPlot;
}
TempText=ExtraText;
while(TempText)
{
if (!TempText->x) TempText->x=XMAXP+10;
if (!TempText->y) TempText->y=abs(YMAXP/4*3)-j;
j=j+20;
TempText=TempText->NextText;
}
return(0);
}
/*****************/
void DrawPlot(Pict)
struct Pict *Pict;
{
struct Plot *Plot, *TempPlot;
short *x, *y, *e, n, m, i;
short tempx1, tempx2, tempy1, tempy2, tempx3, tempy3;
SetDrMd(rp, JAM1);
Plot = Pict->Plot;
while (Plot) {
if (Plot->Enabled) {
SetAPen(rp, Plot->Color);
/* PLOT POINTS */
if (Plot->PointSize > 0) {
TempPlot=Plot;
n = TempPlot->PointSize;
if (abs(n) > 2) {m = (abs(n)/2)-1; SetOPen(rp, Plot->Color);}
if (strlen(Plot->Legend->String)>0)
{
tempx1=Plot->Legend->x+24;
PlotPoint(Plot,&Plot->Legend->x,&Plot->Legend->y,m,n,TRUE);
PlotPoint(Plot,&tempx1,&Plot->Legend->y,m,n,TRUE);
}
do {
x = TempPlot->xp; y = TempPlot->yp;
for (i=0; i<TempPlot->NPts; i++, x++, y++) PlotPoint(TempPlot,x,y,m,n,FALSE);
} while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
}
/* PLOT LINES */
if (Plot->Lines != FALSE) {
switch (Plot->Lines) {
case 6: SetDrPt(rp,0xFCCC); break;
case 5: SetDrPt(rp,0xFF3C); break;
case 4: SetDrPt(rp,0xFFCC); break;
case 3: SetDrPt(rp,0xFFF0); break;
case 2: SetDrPt(rp,0xFF00); break;
case 1:
default: SetDrPt(rp,0xFFFF); break;
}
TempPlot=Plot;
tempx1=(TempPlot->xp[0]); tempy1=(TempPlot->yp[0]);
if (strlen(Plot->Legend->String)>0)
{
PMove(Plot->Legend->x,Plot->Legend->y);
PDraw(Plot->Legend->x+24,Plot->Legend->y);
}
/*** LINE OR LINE & POINT GRAPHS ***/
if (Plot->PlotType<STEP) {
do {
for (i=0; i<TempPlot->NPts; i++) {
tempx3=tempx2=TempPlot->xp[i];
tempy3=tempy2=TempPlot->yp[i];
if (Clip(&tempx1,&tempy1,&tempx2,&tempy2,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(tempx1,tempy1);
PDraw(tempx2,tempy2);
}
tempx1=tempx3;
tempy1=tempy3;
}
} while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
}
/*** STEP GRAPHS ***/
else do {
for (i=0; i<TempPlot->NPts; i++) {
tempx3=tempx2=TempPlot->xp[i];
tempy3=tempy2=TempPlot->yp[i];
if (Clip(&tempx1,&tempy1,&tempx2,&tempy1,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(tempx1,tempy1);
PDraw(tempx2,tempy1);
}
if (Clip(&tempx2,&tempy1,&tempx2,&tempy2,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(tempx2,tempy1);
PDraw(tempx2,tempy2);
}
tempx1=tempx3;
tempy1=tempy3;
}
} while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
SetDrPt(rp,0xFFFF);
}
/* PLOT ERROR BARS */
if ((Pict->ShowErr)&&(Plot->PlotType!=STEP)) {
TempPlot=Plot;
do {
x = TempPlot->xp; y = TempPlot->yp; e = TempPlot->ep;
for (i=0; i < TempPlot->NPts; i++, x++, y++, e++) {
if (abs(*e)>FFPSMALL)
{
tempy1=*y-*e; tempy2=*y+*e;
if (QuickClip(*x,&tempy1,&tempy2,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(*x, tempy1);
PDraw(*x, tempy2);
}
if (ClipPoint(*x,*y-*e,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(*x-ERR_DELIM,*y - *e);
PDraw(*x+ERR_DELIM, *y - *e);
}
if (ClipPoint(*x,*y+*e,XMINP,YMINP,XMAXP,YMAXP))
{
PMove(*x-ERR_DELIM,*y + *e);
PDraw(*x+ERR_DELIM, *y + *e);
}
}
}
} while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
}
}
while (Plot->Continued) Plot=Plot->NextPlot; Plot=Plot->NextPlot;
}
SetDrMd(rp, COMPLEMENT);
}
/*************************************************************/
extern int CheckUser();
extern int GetHowTo();
extern void CleanUp();
extern USHORT chip WaitSprite[];
extern struct Window *window;
extern short SCRIPT_ON;
void plot(Pict)
struct Pict *Pict;
{
struct PlotRegion *Reg;
struct Tics *Tics;
int req;
void CloseFonts();
InitWind(Pict);
if (SCRIPT_ON)
{
AdjustTics(&(Pict->CurrReg->XMin),&(Pict->CurrReg->XMax),Pict->Tics->NX,Pict->Tics->x);
AdjustTics(&(Pict->CurrReg->YMin),&(Pict->CurrReg->YMax),Pict->Tics->NY,Pict->Tics->y);
req = REDRAW;
}
else req = GETDATALIMITS;
GetHowTo(Pict);
Tics = Pict->Tics;
do {
switch(req) {
case GETHOWTO:
GetHowTo(Pict); /* fall thru */
case GETDATALIMITS:
GetDataLimits(Pict);
case REPLOT:
SetPointer(window,WaitSprite,26,14,-4,-4);
Reg = Pict->CurrReg;
if (!Pict->XRegionLock)
AdjustForTics(&Reg->XMin, &Reg->XMax, Tics->NX, Tics->x);
if (!Pict->YRegionLock)
AdjustForTics(&Reg->YMin, &Reg->YMax, Tics->NY, Tics->y);
case REDRAW:
SetPointer(window,WaitSprite,26,14,-4,-4);
AllowForText(Pict);
CheckLegend(Pict);
Scale(Pict);
case REFRESH:
default: ;
}
SetPointer(window,WaitSprite,26,14,-4,-4);
SetRast(rp,0);
DrawAxes(Pict->Tics,Pict->Grid);
DrawPlot(Pict);
ClearPointer(window);
ClearMenuStrip(window); CheckMenu(Pict); SetMenuStrip(window, &Project);
req = CheckUser(Pict);
} while (req != QUIT);
CloseFonts();
CleanUp();
}
/***************************/
void PToU(Pict, xp, yp, x, y)
struct Pict *Pict;
short xp, yp;
FFP *x, *y;
{
*x = Pict->CurrReg->XMin + (FFP)(xp-XMINP) / Pict->XScale;
*y = Pict->CurrReg->YMin + (FFP)(yp-YMINP) / Pict->YScale;
}
PrintVText(rp,PText,X,Y)
struct RastPort *rp;
struct IntuiText *PText;
int X;
int Y;
{
struct TextFont *f;
int height;
int i,n,x,y;
struct TextAttr *at;
static struct TextAttr old_at;
char c;
AskFont(rp,&old_at);
while (PText)
{
SetAPen(rp,PText->FrontPen);
SetBPen(rp,PText->BackPen);
SetDrMd(rp,PText->DrawMode);
at=PText->ITextFont;
f=NULL;
f=(struct TextFont *) OpenFont(at);
if (f) {
SetFont(rp,f);
height=at->ta_YSize+1;
}
else height=CHARHEIGHT+1;
x=X+PText->LeftEdge+TextLength(rp,"M",1);
y=Y+PText->TopEdge;
n=strlen(PText->IText);
for (i=0;i<n;i++)
{
c=PText->IText[i];
Move(rp,abs(x-(TextLength(rp,&c,1)/2)),y+(i*height));
Text(rp,&c,1);
}
CloseFont(f);
PText=PText->NextText;
}
f=(struct TextFont *) OpenFont(&old_at);
SetFont(rp,f);
return(0);
}
void PDrawPlus(m,x,y)
SHORT m,x,y;
{
Move(rp,x-m,MAXVERT-y);
Draw(rp,x+m,MAXVERT-y);
Move(rp,x,MAXVERT-y-m);
Draw(rp,x,MAXVERT-y+m);
}
void PDrawBox(m,x,y)
SHORT m,x,y;
{
SHORT points[10];
points[0]=points[2]=points[8]= x-m;
points[1]=points[7]=points[9]=MAXVERT-y-m;
points[3]=points[5]=MAXVERT-y+m,
points[4]=points[6]=x+m;
Move(rp,x-m,MAXVERT-y-m);
PolyDraw(rp,5,points);
}
void PDrawEggs(m,x,y)
SHORT m,x,y;
{
Move(rp,x-m,MAXVERT-y+m);
Draw(rp,x+m,MAXVERT-y-m);
Move(rp,x+m,MAXVERT-y+m);
Draw(rp,x-m,MAXVERT-y-m);
}
void PDrawKite(m,x,y)
SHORT m,x,y;
{
SHORT points[10];
points[0]=points[4]=points[8]= x;
points[1]=points[9]=MAXVERT-y+m;
points[3]=points[7]=MAXVERT-y,
points[2]=x+m;
points[6]=x-m;
points[5]=MAXVERT-y-m;
Move(rp,x,MAXVERT-y+m);
PolyDraw(rp,5,points);
}
void PDrawTri(m,x,y)
SHORT m,x,y;
{
SHORT points[8];
points[0]=points[6]= x;
points[3]=points[5]=MAXVERT-y+m;
points[1]=points[7]=MAXVERT-y-m,
points[2]=x+m;
points[4]=x-m;
Move(rp,x,MAXVERT-y-m);
PolyDraw(rp,4,points);
}
GetString(tmpstr,x)
char *tmpstr;
FFP x;
{
int n;
if ((x==0.0)||((abs(x)>0.001)&&(abs(x)<99999)))
{
n=sprintf(tmpstr,"%-.3f",x);
while (tmpstr[n-1] == '0') n--;
if (tmpstr[n-1] == '.') n--;
}
else
{
n=sprintf(tmpstr,"%-.2g",x);
if (n>7) n=sprintf(tmpstr,"%-.1g",x);
if (n>7) n=sprintf(tmpstr,"%-.0g",x);
}
if (n<2) {strcat(tmpstr,".0"); n=n+2;}
tmpstr[n]='\0';
return(n);
}